home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7837 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Call order of constructors
  5. Date: Mon, 19 Feb 1996 18:07:20 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4gae7m$7ar@news.halcyon.com>
  8. References: <4ftv2n$kts@ccnet3.ccnet.com>
  9. NNTP-Posting-Host: blv-pm12-ip19.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. O.K., TRANSPORT's ctor accepts a string identifying the transport and
  13. the ctor does of series of strcmpi() calls to match this name.  If a
  14. match is found, the "magic stuff" is initialized appropriately,
  15. otherwise the object initializes in a null-state.  
  16.  
  17. Rather than SESSION testing it's transport for null-state, you'd
  18. rather the TRANSPORT ctor threw an exception.  Look up try, catch, and
  19. throw.  You may also have to set a compiler switch to generate
  20. exception unwinding code.  
  21.  
  22. What is the compiler griping about in your TRANSPORT ctor?
  23.  
  24. BTW, you may want to create a TRANSPORT_FACTORY class
  25. that has a Make method returning a TRANSPORT *.  You can readily add
  26. new transports without having to recompile every client of a
  27. transport.
  28.  
  29.                     --Norm 
  30.  
  31. jantypas@ccnet.com (John Antypas) wrote:
  32.  
  33. >Hello C++ wizards...
  34.  
  35. >I'm trying to create a library access some private netowrk resources. 
  36. >I thought I'd try something like this:
  37.  
  38. >class TRANSPORT {
  39. >    ... magic stuff...
  40. >public:
  41. >    TRANSPORT(char *name)    // Called to activate and bind transport(name)
  42. >    ~TRANSPORT()        // Called when we're done with transport(name)
  43.  
  44. >}
  45.  
  46. >class SESSION(
  47. >    TRANSPORT transport&;
  48. >    ....
  49. >    SESSION(char *transport_name, 
  50. >        char *transport_address);
  51. >    ~SESSION();
  52. >    ....
  53. >}
  54.  
  55. >I was hoping that main code such as :
  56.  
  57. >    SESSION    my_session("iee488", "unit-4B");
  58.  
  59. >would create a session on the IEEE488 controller, to unit Unit-4B, specifically,    - open a trasnport to the IEEE-488 system by calling the IEEE488
  60. >      constructor
  61. >    - open a session by calling the session constructor and have it
  62. >      finish the job.
  63.  
  64. >The destructor sequence runs in the exact reverse.
  65.  
  66. >First off, the compiler complains about the TRANSPORT constructors, second,
  67. >I find myself asking what to do if a constructor or destructor fails?
  68. >How do I catch the error condition to notify outer levels of the program?
  69.  
  70. >Help as always is appreciated.
  71.  
  72. >John Antypas    jantypas@soft21.s21.com
  73.  
  74. >-- 
  75. >John Antypas@21st Century Softwware (jantypas@soft21.s21.com)
  76.  
  77. >"God is too busy to create chaos and disorder in this world, he can't be
  78. > everywhere at once all of the time,  That's why he made two year olds"
  79.  
  80.  
  81.